<?php

/**
 * GotProRoles insertion and edition handler
 * @package ModuleOrganisationCommunication
 * @version 1.0b
 */

session_start();

// Configuration file
include 'configuration.php';
// Functions
include 'inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	header('Location: index.php');
	exit();
endif;

// Include all objects
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

// ---------- START: HEAD
include $configuration['webroot'].'inc/head.php';
// ---------- END: HEAD

// ---------- START: MENU
include $configuration['webroot'].'inc/menu.php';
// ---------- END: MENU

// ---------- START: BODY

if (isset($_GET['operation'])) :

	$gotprorole = new GotProRole();
	$dateFrom = $dateTo = '';
	
	// In case we are in an insert state
	if ($_GET['operation'] == 'add'):
		$company = new Company();
		$contact = new Contact();
		if (isset($_GET['sid'])) $company->Get($_GET['sid']);
		if (isset($_GET['cid'])) $contact->Get($_GET['cid']);
		$gotprorole->SetCompany($company);
		$gotprorole->SetContact($contact);
	
	// In case we are in an update state
	elseif (($_GET['operation'] == 'edit') && isset($_GET['id'])):
		$gotprorole->Get($_GET['id']);
		$company = $gotprorole->GetCompany();
		$contact = $gotprorole->GetContact();
		if (strlen($gotprorole->from) > 0):
			$dateFrom = explode('-', $gotprorole->from);
			$dateFrom = $dateFrom[2].'/'.$dateFrom[1].'/'.$dateFrom[0];
		endif;
		if (strlen($gotprorole->to) > 0):
			$dateTo = explode('-', $gotprorole->to);
			$dateTo = $dateTo[2].'/'.$dateTo[1].'/'.$dateTo[0];
		endif;
	endif;

	include 'forms/prorole.php';

endif;
// ---------- END: BODY

// ---------- START: FOOT
include $configuration['webroot'].'inc/foot.php';
// ---------- END: FOOT

// ---------- JAVASCRIPTS AND END
include $configuration['webroot'].'inc/js.php'; ?>
<script type="text/javascript" src="js/proroles.js"></script>

</body>
</html>